import unittest
from random import randint
from random import choice
from faker import Faker
from time import sleep

from urllib3.util import assert_fingerprint

from login.oa import login
from random_cn import *
fa = Faker(locale='zh_CN')
class Oa_ckgg(unittest.TestCase):  #查看公告
    def setUp(self):
        self.driver = login()
    def tearDown(self):
        sleep(2)
        self.driver.close()
    def test_01(self):
        #进入查看公告
        self.driver.find_element('xpath', '//*[@id="leftmenuDiv"]/h3[2]/span').click()
        self.driver.find_element('xpath','//*[@id="leftmenuDiv"]/div[2]/table/tbody/tr[6]/td/a').click()
        assert self.driver.find_element('xpath','//*[@id="locationtext"]').text == '查看公告','进入查看公告错误'
        #筛选查询
        self.driver.switch_to.frame(self.driver.find_element('xpath','//*[@id="iframe_main"]'))
        a = randint(1,5)
        if a == 1:  #标题搜索
            chr = []
            for j in cn():
                chr.append(j)
            q = choice(chr)
            self.driver.find_element('xpath','//*[@id="myform"]/div[1]/div/div[1]/select/option[1]').click()
            self.driver.find_element('xpath','//*[@id="subject"]').send_keys(q)
            self.driver.find_element('xpath','//*[@id="searchButton"]/img').click()#查询
            if self.driver.find_element('xpath','//*[@id="__gt_FGrid_r_-204461936252010238"]/td[2]/div/a').text ==None:     #判断是否有值
                pass
            else:
                self.assertIn(q,self.driver.find_element('xpath','//*[@id="__gt_FGrid_r_-204461936252010238"]/td[2]/div/a').text,msg='标题查询错误')
        elif a == 2:    #类别搜索
            self.driver.find_element('xpath','//*[@id="myform"]/div[1]/div/div[1]/select/option[3]').click()
            if a == 1:  #行政公告
                self.driver.find_element('xpath','//*[@id="categoryId"]/option[1]').click()
                self.driver.find_element('xpath', '//*[@id="searchButton"]/img').click()  # 查询
                if self.driver.find_element('xpath','//*[@id="categoryId"]/option[1]').text == None:    #判断是否有值
                    pass
                else:   #其他公告
                    assert(self.driver.find_element('xpath','//*[@id="categoryId"]/option[1]').text == self.driver.find_element('xpath','//*[@id="__gt_FGrid_r_-204461936252010238"]/td[3]/div').text,'类别查询失败')
            else:
                self.driver.find_element('xpath','//*[@id="categoryId"]/option[2]').click()
                self.driver.find_element('xpath', '//*[@id="searchButton"]/img').click()  # 查询
                if self.driver.find_element('xpath', '//*[@id="categoryId"]/option[2]').text == None:   #判断是否有值
                    pass
                else:
                    assert (
                    self.driver.find_element('xpath', '//*[@id="categoryId"]/option[2]').text == self.driver.find_element(
                        'xpath', '//*[@id="__gt_FGrid_r_-204461936252010238"]/td[3]/div').text, '类别查询失败')
        elif a == 3:    #发布人
            self.driver.find_element('xpath','//*[@id="myform"]/div[1]/div/div[1]/select/option[4]').click()
            self.driver.find_element('xpath','//*[@id="createEmpName"]').send_keys('系统管理员')
            self.driver.find_element('xpath', '//*[@id="searchButton"]/img').click()  # 查询
            if self.driver.find_element('xpath','//*[@id="__gt_FGrid_r_-204461936252010238"]/td[5]/div').text == None:
                pass
            else:
                assert self.driver.find_element('xpath','//*[@id="__gt_FGrid_r_-204461936252010238"]/td[5]/div').text == '系统管理员','发布人查询失败'
        elif a == 4:    #发布日期
            self.driver.find_element('xpath','//*[@id="myform"]/div[1]/div/div[1]/select/option[5]').click()
            self.driver.find_element('xpath','//*[@id="createTimeDiv"]/input[1]').click()
            self.driver.find_element('xpath','//*[@id="dpTodayInput"]').click()
            self.driver.find_element('xpath','//*[@id="createTimeDiv"]/input[2]').click()
            self.driver.find_element('xpath','//*[@id="dpTodayInput"]').click()
            self.driver.find_element('xpath', '//*[@id="searchButton"]/img').click()  # 查询
        elif a == 5:    #内容查询
            self.driver.find_element('xpath','//*[@id="myform"]/div[1]/div/div[1]/select/option[2]').click()
            self.driver.find_element('xpath','//*[@id="content"]').send_keys(cn1())
        #刷新
        self.driver.switch_to.default_content()
        self.driver.find_element('xpath','//*[@id="div_navbutton"]/div[5]/button[3]/img').click()
        self.driver.switch_to.frame(self.driver.find_element('xpath','//*[@id="iframe_main"]'))
        #进入详情页
        self.driver.find_element('xpath','//*[@id="__gt_FGrid_r_-204461936252010238"]/td[2]/div/a').click()










if __name__ == '__main__':
    unittest.main()
